import json

from tensorflow import keras

from src.utils.config import config
from src.utils.model_utils import get_level_id_mapping

# 模型数据的时间跨度
MODEL_DAYS = 60
# 环保机等级模板ID
EVN_TEMPLATE_ID = '442'

TABLET_COLUMNS_MAPPING = {'内存': 'memory', '苹果保修期时长': 'guarantee', '储存容量': 'storage',
                          '网络模式': 'networks', '购买渠道': 'purchase_way', '颜色': 'color'}
# 等级ID和名称映射
TABLET_LEVEL_ID_MAPPING = get_level_id_mapping(6)

# 模型特征
TABLET_FEATURES = ['product_name', 'product_brand_name', 'product_level_name', 'product_level_template_id',
                   'memory', 'guarantee', 'storage', 'networks', 'purchase_way', 'color', 'period']

# 模型保存时间
KEEP_MODEL_DAYS = 180
# 模型推送到的服务器
MODEL_PUSH_SERVERS = json.loads(config.get_config('model', 'model_servers'))
# 模型API接口
MODEL_SERVER_PORTS = json.loads(config.get_config('model', 'model_server_ports'))

# 模型路径
MODEL_DIR = 'models/tablet/'
# 模型名称
MODEL_FILE_NAME = 'tablet_price.h5'
TABLET_OHE_NAME = 'tablet_ohe.pkl'
TABLET_SCALER_NAME = 'tablet_scaler.pkl'
TABLET_PRODUCT_OHE_NAME = 'tablet_product_ohe.pkl'

# 配置模型早停
early_stop = keras.callbacks.EarlyStopping(monitor='val_loss', patience=70)
# 模型callback设置
model_callbacks = [early_stop]

# 计算历史均价周期
TABLET_HISTORY_AVG_PRICE_DAYS = 7
TABLET_HISTORY_AVG_PRICE_PREFIX = 'thap_'
# 历史均价缓存时长
TABLET_HISTORY_CACHE_TIME = 60 * 60 * 36
